import {createRouter, createWebHashHistory} from 'vue-router'
import type {RouteRecordRaw} from 'vue-router'
import HomeView from '../packages/front/landing/views/HomeView.vue'

import layoutIndex from "@/packages/admin/layout/views/layout-index.vue"
import {businessRouter} from "@/router/businessRouter";
import {adminRouterPath} from "@/router/config";


/**
 * 错误由路由
 */
export const errotRoutes: RouteRecordRaw[] = [
    {
        path: '/404',
        component: () => import('@/views/error-page/404.vue'),
        meta: {"title": "404"}
    },
    {
        path: '/401',
        component: () => import('@/views/error-page/401.vue'),
        meta: {"title": "401"}
    },
    {
        path: '/:pathMatch(.*)',
        component: () => import('@/views/error-page/404.vue'),
    }
]

/**
 * 前端页路由
 */
export const frontRoutes: RouteRecordRaw[] = [
    {
        path: '/',
        name: 'home',
        component: HomeView,
        meta: {"title": "首页", "icon": "House"},
        children: []
    },
    {
        path: '/about',
        name: 'about',
        component: () => import("../packages/front/landing/views/AboutView.vue"),
        meta: {"title": "关于"}
    },
    {
        path: '/login',
        component: () => import('@/packages/admin/login/views/admin-login.vue')
    }

]


/**
 * 运维端路由
 */
export const adminRoutes: RouteRecordRaw[] = [

    {
        path: 'test',
        name: 'test',
        component: () => import("@/packages/admin/test/test1.vue"),
        meta: {"title": "测试1", "icon": "barchart", multiplex: true}
    },
    {
        path: 'test2/:id',
        name: 'test2',
        component: () => import("@/packages/admin/test/test2.vue"),
        meta: {"title": "test2", "icon": "barchart", multiplex: true}
    },
    {
        path: 'dashboard',
        name: 'dashboard',
        component: () => import("@/packages/admin/dashboard/views/admin-dashboard.vue"),
        meta: {"title": "指标面板", "icon": "barchart"}
    },
    {
        path: 'user',
        name: 'usermanager',
        component: () => import("@/packages/admin/user/views/user-index.vue"),
        meta: {"title": "员工管理"}
    },
    {
        path: 'dept',
        name: 'admindept',
        component: () => import("@/packages/admin/user/views/dept-index.vue"),
        meta: {"title": "机构管理"}
    },
    {
        path: 'menu',
        name: 'AdminMenu',
        component: () => import("@/packages/admin/menu/views/menu-index.vue"),
        meta: {"title": "菜单管理"}
    },
    {
        path: 'role',
        name: 'AdminRole',
        component: () => import("@/packages/admin/role/role-index.vue"),
        meta: {"title": "角色管理"}
    },
    {
        path: 'privilege',
        name: 'Adminprivilege',
        component: () => import("@/packages/admin/role/privilege-index.vue"),
        meta: {"title": "自定义权限"}
    },
    {
        path: 'tenant',
        name: 'Admintenant',
        component: () => import("@/packages/admin/tenant/tenant-index.vue"),
        meta: {"title": "租户管理"}
    },
    {
        path: 'notice',
        name: 'AdminNotice',
        component: () => import("@/packages/admin/notice/notice-index.vue"),
        meta: {"title": "公告管理"}
    },
    {
        path: 'enum',
        name: 'AdminEnum',
        component: () => import("@/packages/admin/enum/index.vue"),
        meta: {"title": "字典管理"}
    },
    {
        path: 'var',
        name: 'AdminVar',
        component: () => import("@/packages/admin/var/index.vue"),
        meta: {"title": "参数管理"}
    },
    {
        path: 'xzq',
        name: 'AdminXzq',
        component: () => import("@/packages/admin/xzq/index.vue"),
        meta: {"title": "行政区管理"}
    },
    {
        path: 'tenantself',
        name: 'AdminTenant',
        component: () => import("@/packages/admin/tenant/tenant-self.vue"),
        meta: {"title": "租户自我管理"}
    },
    {
        path: 'combo',
        name: 'AdminCombo',
        component: () => import("@/packages/admin/tenant/combo-index.vue"),
        meta: {"title": "租户套餐"}
    },
    ...businessRouter
]

/**
 * 常用路由
 * 没有权限要求的基本页
 * 可以访问所有角色
 */
export const allRoutes: RouteRecordRaw = {

    path: adminRouterPath,
    name: "admin",
    component: layoutIndex,
    redirect: adminRouterPath + '/index',
    meta: {"title": "后台", "icon": "barchart", "breadcrumb": false},
    children: [
        {
            path: 'index',
            name: 'index',
            component: () => import("@/packages/admin/dashboard/views/admin-index.vue"),
            meta: {"title": "首页", "icon": "barchart", url: adminRouterPath + '/index', notInTab: true}
        },
        {
            path: 'profile/password',
            name: 'password',
            component: () => import("@/packages/admin/profile/password.vue"),
            meta: {"title": "密码修改", "url": adminRouterPath + '/profile/password'}
        },
        {
            path: 'iframe',
            name: 'iframe',
            component: () => import("@/packages/admin/layout/views/layout-iframe.vue"),
            meta: {"title": "iframe地址", "url": adminRouterPath + '/iframe', iframe: true, multiplex: true}
        },
        {
            path: 'test3/:id',
            name: 'test3',
            component: () => import("@/packages/admin/test/test3.vue"),
            meta: {"title": "test3", "icon": "barchart", multiplex: true}
        },
    ]

}


const router = createRouter({
    history: createWebHashHistory(import.meta.env.BASE_URL),
    routes: frontRoutes
})

export default router
